//
//  BillLinesView.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/11/26.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

class BillLinesView: UIView {
    
    fileprivate let leftView = UIView()
    fileprivate let rightView = UIView()
    
    fileprivate let allLinesImage = UIImageView()
    fileprivate let allLinesTipLabel = UILabel()
    fileprivate let allLinesLabel = UILabel() //总额度
    
    fileprivate let remainLinesImage = UIImageView()
    fileprivate let remainLinesTipLabel = UILabel()
    fileprivate let remainLinesLabel = UILabel() //账单额度

    init(model:InputBillModel) {
        super.init(frame: .zero)
        
        leftView.backgroundColor = UIColor.white
        self.addSubview(leftView)
        
        rightView.backgroundColor = UIColor.white
        self.addSubview(rightView)
        
        allLinesImage.image = UIImage.init(named: "surplus")
        leftView.addSubview(allLinesImage)
        
        remainLinesImage.image = UIImage.init(named: "all")
        rightView.addSubview(remainLinesImage)
        
        allLinesLabel.text = model.cardLines
        allLinesLabel.font = UIFont.boldSystemFont(ofSize: RATIO(maxNum: 20))
        leftView.addSubview(allLinesLabel)
        
        if model.isPay == "1" {
            remainLinesLabel.text = model.billLines
        }else{
            remainLinesLabel.text = "\(Int(model.cardLines!)! - Int(model.billLines!)!)"
        }
        remainLinesLabel.font = UIFont.boldSystemFont(ofSize: RATIO(maxNum: 20))
        rightView.addSubview(remainLinesLabel)
        
        allLinesTipLabel.text = allLines
        allLinesTipLabel.textColor = UIColor.lightGray
        allLinesTipLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        leftView.addSubview(allLinesTipLabel)
        
        remainLinesTipLabel.text = remainingAmount
        remainLinesTipLabel.textColor = UIColor.lightGray
        remainLinesTipLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        rightView.addSubview(remainLinesTipLabel)
        
        leftView.snp.makeConstraints { (make) in
            make.centerY.left.equalToSuperview()
            make.height.equalTo(RATIO_H(maxNum: 80))
            make.width.equalTo(ScreenW/2-0.5)
        }
        
        rightView.snp.makeConstraints { (make) in
            make.centerY.right.equalToSuperview()
            make.height.width.equalTo(leftView)
        }
        
        allLinesLabel.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(RATIO_H(maxNum: 15))
            make.centerX.equalToSuperview().offset(RATIO(maxNum: 22))
            make.width.greaterThanOrEqualTo(10)
            make.height.equalTo(RATIO_H(maxNum: 25))
        }
        
        allLinesTipLabel.snp.makeConstraints { (make) in
            make.top.equalTo(allLinesLabel.snp.bottom)
            make.left.equalTo(allLinesLabel)
            make.height.equalTo(allLinesLabel)
            make.width.greaterThanOrEqualTo(10)
        }
        
        allLinesImage.snp.makeConstraints { (make) in
            make.width.height.equalTo(RATIO_H(maxNum: 40))
            make.centerY.equalToSuperview()
        make.right.equalTo(allLinesLabel.snp.left).offset(RATIO(maxNum: -4))
        }
        
        remainLinesLabel.snp.makeConstraints { (make) in
            make.top.equalTo(allLinesLabel)
            make.centerX.equalToSuperview().offset(RATIO(maxNum: 22))
            make.width.greaterThanOrEqualTo(10)
            make.height.equalTo(allLinesLabel)
        }
        
        remainLinesTipLabel.snp.makeConstraints { (make) in
            make.top.equalTo(remainLinesLabel.snp.bottom)
            make.left.equalTo(remainLinesLabel)
            make.height.equalTo(allLinesTipLabel)
            make.width.greaterThanOrEqualTo(10)
        }
        
        remainLinesImage.snp.makeConstraints { (make) in
            make.width.height.equalTo(RATIO_H(maxNum: 40))
            make.centerY.equalToSuperview()
        make.right.equalTo(remainLinesLabel.snp.left).offset(RATIO(maxNum: -4))
        }
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
